<?php echo $this->render('/public/header'); ?>
<?php use yii\helpers\Url; ?>
    <link href="/statics/css/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="/statics/css/css/style.css" rel="stylesheet"/>
    <div id="main" class="col-xs-12">

        <div class="tree well">
            <ul>
                <?php foreach ($this->params['list'] as $k => $v) {
                    ; ?>
                    <li class="parent_li">
                        <span title="Collapse this branch"><i
                                    class="icon-folder-open"></i><?php echo $v['name']; ?></span>
                        <a href="javascript:void(0)" onclick="add_more(<?php echo $v['id']; ?>)">
                            <span><i class="glyphicon glyphicon-plus"></i></span>
                        </a>
                        <a href="javascript:void(0)" onclick="remove(<?php echo $v['id']; ?>)">
                            <span><i class="glyphicon glyphicon-minus"></i></span>
                        </a>
                        <ul>
                            <?php if ($v['children']) { ?>
                                <?php foreach ($v['children'] as $k2 => $v2) { ?>
                                    <li class="parent_li">
                                        <span title="Collapse this branch"><i
                                                    class="icon-folder-open"></i><?php echo $v2['name']; ?></span>
                                        <a href="javascript:void(0)" onclick="add_more(<?php echo $v2['id']; ?>)">
                                            <span><i class="glyphicon glyphicon-plus"></i></span>
                                        </a>
                                        <a href="javascript:void(0)" onclick="remove(<?php echo $v2['id']; ?>)">
                                            <span><i class="glyphicon glyphicon-minus"></i></span>
                                        </a>
                                        <?php if (!empty($v2['children'])) {
                                            foreach ($v2['children'] as $k3 => $v3) { ?>
                                                <ul>
                                                    <li class="parent_li">
                                                        <span title="Collapse this branch"><i
                                                                    class="icon-folder-open"></i><?php echo $v3['name']; ?></span>
                                                    </li>
                                                </ul>
                                            <?php }
                                        } ?>
                                    </li>
                                <?php } ?>
                            <?php } ?>
                        </ul>
                    </li>
                <?php } ?>
            </ul>
        </div>

    </div>
    <input type="hidden" id="hidden_id" value=""/>
    <script>
        function add_more(v) {
            $("#hidden_id").val(v);
            zeroModal.show({url: '/api/template_action_list'});
            return false;
        }
    </script>
    <script>
        $(function () {

            $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');

            $('.tree li.parent_li > span').on('click', function (e) {

                var children = $(this).parent('li.parent_li').find(' > ul > li');

                if (children.is(":visible")) {

                    children.hide('fast');

                    $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');

                } else {

                    children.show('fast');

                    $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');

                }

                e.stopPropagation();

            });

        });

    </script>
<?php echo $this->render('/public/footer'); ?>